from django.shortcuts import render

# Create your views here.

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.generics import ListAPIView,CreateAPIView,RetrieveAPIView

from utils.tencent.oss import get_credential

from apps.publish import serializers
from apps.publish.serializers import TopicSerializers,PublishModelSerializer,PublishImageSerializers
from apps.publish.models import TopicModel,PublishModel,PublishImageModel

# 上传图片到腾讯云cos
class OssCredentialView(APIView):
    def get(self,request):

        return Response(get_credential())


# 话题视图
class TopicView(ListAPIView):
    queryset = TopicModel.objects.all()
    serializer_class = TopicSerializers


# 发布视图
class PublishView(CreateAPIView):
    serializer_class = PublishModelSerializer

    def perform_create(self, serializer):
        print(f"前端传来的数据：{self.request.data}")
        publish_obj = serializer.save(user_id=1)
        print(f"存入数据库：{publish_obj}")
        return publish_obj




